<template>
  <div>
    <van-nav-bar @click-left="onClickLeft" left-text="返回" left-arrow />

    <div class="nav">
      <van-address-list
        v-model="chosenAddressId"
        :list="list"
        default-tag-text="默认"
        add-button-text="更换地址"
        @add="onAdd"
        @edit="onEdit"
      />

      <van-submit-bar :price="0" button-text="立即支付" @submit="onSubmit" />
    </div>
  </div>
</template>

<script>
import { Toast } from "vant";
import { reqshuju } from "../../api/cart";
export default {
  data() {
    return {
      chosenAddressId: "1",
      list: [
        {
          id: "1",
          name: "",
          tel: "",
          address: "",
          isDefault: true,
        },
      ],
    };
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1);
    },

    async zhifushuju() {
      const res = await reqshuju();
      console.log(res);
      this.list[0].name = res.orders[0].receiver;
      this.list[0].address = res.orders[0].regions + res.orders[0].address;
      const ss = res.orders.map((item) => {
        let num = 0;
        // console.log(item.price);
        num += item.price;
        return num;
      });
      console.log(ss);
    },
    onAdd() {
      Toast("新增地址");
    },
    onEdit(item, index) {
      this.$router.push("/address");
    },
    onSubmit() {
      Toast("暂未开通此服务");
    },
  },
  created() {
    this.zhifushuju();
  },
};
</script>

<style scoped>
.nav {
  position: relative;
}
.van-address-list__bottom {
  position: absolute;
}
</style>
